#include "stm32f10x.h"

//Data width switch
#ifndef __FSMC_DATA_WIDTH
#define __FSMC_DATA_WIDTH
	#define __USE_FSMC_DATA_16B
	#ifndef __USE_FSMC_DATA_16B
		#define __USE_FSMC_DATA_8B
	#endif
#endif

//ADDR define
#define NORADDR		((uint32_t)0x60000000)
#define NORBANK1	((uint32_t)0x64000000)
#define NORBANK2	((uint32_t)0x68000000)
#define NORBANK3	((uint32_t)0x6C000000)

#define FPGA_CMD_ADDR		((uint32_t)0x60000000)
//#define FPGA_DAT_ADDR		((uint32_t)0x60000001)
//#define FPGA_DAT_ADDR		((uint32_t)0x600f0000)
#define FPGA_DAT_ADDR		((uint32_t)0x60020000)

//Read & Write fun
#ifdef __USE_FSMC_DATA_16B
	#define fpga_Write(offset, data)	*((volatile u16*)(NORADDR + (offset << 17))) = data
	#define fpgaWriteCMD(data)				*((volatile u16*)FPGA_CMD_ADDR) = data
	#define fpgaWriteDAT(data)				*((volatile u16*)FPGA_DAT_ADDR) = data

	#define fpga_Read(offset)					*((volatile u16*)(NORADDR + (offset << 17)))
/*	#define fpga_Write(offset, data)	*((volatile u8*)(NORADDR + (offset << 17))) = data
	#define fpgaWriteCMD(data)				*((volatile u8*)FPGA_CMD_ADDR) = data
	#define fpgaWriteDAT(data)				*((volatile u8*)FPGA_DAT_ADDR) = data
	
	#define fpga_Read(offset)					*((volatile u8*)(NORADDR + (offset << 17)))*/
#endif
#ifdef __USE_FSMC_DATA_8B
	#define fpga_Write(offset, data)	*((volatile u8*)(NORADDR + (offset << 16))) = data
	#define fpgaWriteCMD(data)				*((volatile u8*)FPGA_CMD_ADDR) = data
	#define fpgaWriteDAT(data)				*((volatile u8*)FPGA_DAT_ADDR) = data
	
	#define fpga_Read(offset)					*((volatile u8*)(NORADDR + (offset << 16)))
#endif

void FSMC_FPGA_Init(void);


